import BaseUtil from '@/BaseUtil';
import MathUtil from '@/MathUtil';
import RandomUtil from '@/RandomUtil';
import SelectUtil from '@/SelectUtil';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 雷霆之怒
 **/
export default class BossSpell_StromFury extends AbilityBase {
    static instance: BossSpell_StromFury;
    constructor(id: string = 'Myh4') {
        super(id);
        BossSpell_StromFury.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('雷霆之怒', source);
        StunSystemIntance.stun(source, 10);
        let ef = AddSpecialEffect('SuperLightningBall.mdx', GetUnitX(source), GetUnitY(source));
        EXSetEffectZ(ef, 90);
        let ux = GetUnitX(source);
        let uy = GetUnitY(source);
        BaseUtil.runLater(1, () => {
            BaseUtil.onTimer(0.25, (c) => {
                let { x, y } = MathUtil.polarProjection(ux, uy, RandomUtil.nextInt(50, 800), RandomUtil.randomAngle());
                let mark = AddSpecialEffect(BossAbilityManagerInstance.SpellMark, x, y);
                BaseUtil.runLater(1, () => {
                    DestroyEffect(mark);
                    mark = null;
                    DestroyEffect(AddSpecialEffect('50.mdx', x, y));
                    let es = SelectUtil.getEnemyUnitsInRange(source, 125, x, y);
                    if (es.length > 0) DamageSystemInstance.applyAoeMagicDamage(es, source, 1000, 'lighting');
                    if (c >= 20) {
                        source = null;
                        ef = null;
                    }
                });

                if (c >= 20) {
                    DestroyEffect(ef);
                }
                return c < 40;
            });
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
